using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Universal.Api.Attributes;
using Universal.Application.Contracts.Dto.Log;
using Universal.Application.Repositories;

namespace Universal.Api.Controllers;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class LogController : ControllerBase
{
    private readonly ILogService _logService;

    public LogController(ILogService logService)
    {
        _logService = logService;
    }

    /// <summary>
    /// 基本分页获取日志列表
    /// </summary>
    [HttpGet("paged")]
    [RequirePermission("log.View")]
    public async Task<IActionResult> GetLogsPagedAsync([FromQuery] int pageIndex, [FromQuery] int pageSize)
    {
        var result = await _logService.GetLogsPagedAsync(pageIndex, pageSize);
        return Ok(result);
    }

    /// <summary>
    /// 查询日志列表（支持时间范围过滤）
    /// </summary>
    [HttpGet("query")]
    [RequirePermission("log.View")]
    public async Task<IActionResult> QueryLogsAsync([FromQuery] LogQueryDto queryDto)
    {
        var result = await _logService.QueryLogsAsync(queryDto);
        return Ok(result);
    }
}
